{template header}
<style type="text/css">
    .bg{display:none;position:fixed;width:100%;height:100%;background:#000;z-index:2;top:0;left:0;opacity:0.7;}
</style>
<h4 style="padding-left:10px;;">
    <a href="?c=admin&a=getHotRepairList"><span>热修复管理</span></a>
    >>
    <a href="?c=admin&a=addHotRepair"><span>创建/编辑补丁</span></a>
</h4>
<script type="text/javascript">
    function uploadImage() {
        if($("#imgFile").val() != '') $("#upload_form").submit();
    }
    function upload_frame_load() {
        var data = $(window.frames['upload_frame'].document.body).html();
        if(data) {
            data = eval('(' + data + ')');
            //console.log(data);return false;
            if(data.status=='ok'){
                var _this= $('#showImage');
                var _html = '';
                 _html +=
                        '<tr>'
                        +'<td>'+data.file_name+'</td>'
                        +'<td>'+data.file_hash+'</td>'
                        +'<td style="display: none"><input type="hidden" name="fileName[]" value="'+data.file_name+'" /></td>'
                        +'<td style="display: none"><input type="hidden" name="image[]" value="'+data.image+'" /></td>'
                        +'<td><a href="javascript:void(0);" class="delNew" >删除</a></td>'
                        +'</tr>';
                _this.append(_html);
            }else{
                alert(data.error_msg);
            }
        }
    }
</script>
<div id="fream">
    <form id="upload_form" method="post" action="?c=admin&a=ajaxUploadRepair" target="upload_frame" enctype="multipart/form-data">
        <input type="file" name="imgFile" id="imgFile" style="display:none;" onchange="uploadImage();">
    </form>
    <iframe id="upload_frame" name="upload_frame" style="display:none" onLoad="upload_frame_load();"></iframe>
</div>
<form class="form-horizontal"  action="?c=admin&a=ajaxAddHotRepair"  id="tr_form">
    <input type="hidden" name="repairId" value="{$repairId}"/>
    <div class="control-group">
        <label class="control-label" >客户端：</label>
        <div class="controls">
            <select name="clientId">
                <option value="1" {if isset($info['client_type']) && $info['client_type'] == 1}selected="selected"{/if} >安卓</option>
                <option value="2" {if isset($info['client_type']) && $info['client_type'] == 2}selected="selected"{/if} >IOS</option>
            </select>
        </div>
    </div>

    <!--<div class="control-group">-->
        <!--<label class="control-label" >数字版本号：</label>-->
        <!--<div class="controls">-->
            <!--<input type="text" value="" name="patchVersion" placeholder="" />-->
        <!--</div>-->
    <!--</div>-->
    <div class="control-group">
        <label class="control-label" >客户端版本号：</label>
        <div class="controls">
            <input type="text" value="{if !empty($info['app_version'])}{$info['app_version']}{/if}" name="appVersion" placeholder="多个用,号隔开" />
        </div>
    </div>


    <div class="control-group">
        <label class="control-label" >  文件清单：</label>
        <div class="controls">
            <button type="button" id="file_upload_btn" class="btn btn-primary" onclick="$('#imgFile').trigger('click')">
                <i class="ace-icon fa fa-cloud-upload bigger-110"></i>添加文件
            </button>
        </div>
    </div>

    <div class="control-group">
        <div class="controls">
            <table style="width: 80%" border="1" id="showImage">
                <thead>
                <tr>
                    <td>文件名</td>
                    <td>文件特征码</td>
                    <td style="display: none;"></td>
                    <td style="display: none;"></td>
                    <td>操作</td>
                </tr>
                {if isset($info['patchList']) && !empty($info['patchList'])}
                    {loop $info['patchList'] $k $v}
                        <tr>
                            <td>{$v['file_name']}</td>
                            <td>{$v['file_hash']}</td>
                            <td style="display: none;"><input type="hidden" name="fileName[]" value="{$v['file_name']}" /></td>
                            <td style="display: none;"><input type="hidden" name="image[]" value="{$v['file_url']}" /></td>
                            <td><a href="javascript:void(0);" class="delNew" >删除</a></td>
                        </tr>
                    {/loop}
                {/if}
                </thead>
            </table>
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <span class="btn btn-primary" type="button" id="qd">确定</span>
        </div>
    </div>
</form>
{template footer}
<script type="text/javascript">
    /*删除*/
    $(document).on('click',".delNew",function(){
        var _this=$(this),_tr=_this.parent().parent();
        _tr.remove();
    })

    $(document).on("click",".delimages", function () {
        var _this=$(this),_del = $(this).prev('span');
        _del.remove();
        _this.remove();
    })
    $('#qd').on('click',function(){
        $.ajax({
            type:'POST',
            url:$('#tr_form').attr('action'),
            data:$('#tr_form').serialize(),
            dataType:'json',
            success:function(d){
                if(d.status=='ok'){
                    alert(d.error_msg);
                    window.location.href=d.url;
                }else{
                    alert(d.error_msg);
                }
            }
        })
    })
</script>